package offer;

import linkedList.ListNode;

import java.util.ArrayList;
import java.util.*;

public class ListNodeQuestion {
    public static void main(String[] args) {

    }
    //从尾到头打印链表
    public int[] reversePrint(ListNode head) {
        //第一种方法  递归
        ListNode temp = head;
        Stack<ListNode> stack = new Stack<>();
        while(temp != null){
            stack.add(temp);
            temp = temp.next;
        }
        int len = stack.size();
        int[] result = new int[len];
        for (int i = 0; i < len; i++) {
            result[i] = stack.pop().val;
        }
        return result;
    }

    //反转链表
    public ListNode reverseList(ListNode head) {
        ListNode newHead = new ListNode(0);
        ListNode temp = head;
        ListNode cur = head;
        while(temp != null){
            cur = temp.next;
            temp.next = newHead.next;
            newHead.next = temp;
            temp = cur;
        }
        return newHead.next;
    }

    //复杂链表的复制
    public Node copyRandomList(Node head) {
        if (head == null)return null;
        Node node = new Node(0);
        Node temp = head;
        while(temp != null){
        }
        return node;
    }
}
